#pragma once

#include "Interval.h"

#include "ValueSpecification.h"

namespace uml {

Interval::Interval(const QString& umlType)
    : ValueSpecification(umlType) {}

void Interval::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    ValueSpecification::fromJson(json, errorList);
    max_ = JsonSerializable::create<ValueSpecification>(json.value("max"), errorList);

    min_ = JsonSerializable::create<ValueSpecification>(json.value("min"), errorList);

}

void Interval::toJson(QJsonObject& json) {
    ValueSpecification::toJson(json);
    if (max_) {
        QJsonObject max_json;
        max_->toJson(max_json);
        json.insert("max", max_json);
    }
    if (min_) {
        QJsonObject min_json;
        min_->toJson(min_json);
        json.insert("min", min_json);
    }
}

/// <summary>
/// max getter
/// Refers to the ValueSpecification denoting the maximum value of the range.
/// </summary>
shared_ptr<ValueSpecification> Interval::max() const {
    return max_;
}

/// <summary>
/// max setter
/// Refers to the ValueSpecification denoting the maximum value of the range.
/// </summary>
void Interval::setMax(shared_ptr<ValueSpecification> value) {
    max_ = value;
}

/// <summary>
/// min getter
/// Refers to the ValueSpecification denoting the minimum value of the range.
/// </summary>
shared_ptr<ValueSpecification> Interval::min() const {
    return min_;
}

/// <summary>
/// min setter
/// Refers to the ValueSpecification denoting the minimum value of the range.
/// </summary>
void Interval::setMin(shared_ptr<ValueSpecification> value) {
    min_ = value;
}

} // namespace uml
